package com.infore.dataAudit.controller;

import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;

import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.infore.dataAudit.service.audit.IAuditExportService;
import com.infore.dataAudit.util.ResultEntity;
import com.infore.dataAudit.vo.AuditRecordQuery;
import com.infore.dataAudit.vo.QualityParamOutSelectBo;

@RestController
@RequestMapping("/export")
public class AuditExportController {
	
    @Autowired
    private IAuditExportService auditExportService;
    
	@RequestMapping(value = "/auditRecordExport", method = RequestMethod.GET )
	public void auditRecordDatasExport( AuditRecordQuery query, HttpServletResponse response) { 
	    try {
            byte[] bytes = auditExportService.auditRecordDatasExport(query);
            //byte[] bytes = auditExportService.autoStationMultiReportExport();
            if (bytes != null) {
                String filename = "审核日志报表";
                filename = java.net.URLEncoder.encode(filename + ".xls",
                        "UTF-8");
                response.reset();
                response.addHeader("Content-Disposition","attachment;filename=" + new String(filename.getBytes()));
                response.addHeader("Content-Length", "" + bytes.length);
                response.setContentType("application/vnd.ms-excel;charset=utf-8");
                OutputStream toClient = new BufferedOutputStream(response.getOutputStream());
                toClient.write(bytes);
                toClient.flush();
                toClient.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
            String filename = "导出失败";
            response.setContentType("text/plain;charset=utf-8");
            try {
                response.getWriter().write(filename);
            } catch (IOException e1) {
                e1.printStackTrace();
            }

        }
	}

}
